<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>旋转数组 - 算法详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
        }
        .hero-gradient {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-5px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .code-block {
            background: #282c34;
            color: #abb2bf;
            border-radius: 12px;
            overflow: hidden;
        }
        .code-block pre {
            margin: 0;
            padding: 1.5rem;
            overflow-x: auto;
        }
        .keyword { color: #c678dd; }
        .function { color: #61afef; }
        .string { color: #98c379; }
        .number { color: #d19a66; }
        .comment { color: #5c6370; font-style: italic; }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            color: #667eea;
            font-family: 'Noto Serif SC', serif;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .complexity-badge {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            padding: 0.25rem 0.75rem;
            border-radius: 9999px;
            font-size: 0.875rem;
            font-weight: 500;
            display: inline-block;
            margin: 0.25rem;
        }
        .step-number {
            width: 2.5rem;
            height: 2.5rem;
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            color: white;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            font-weight: 700;
            flex-shrink: 0;
        }
    </style>
</head>
<body>
    <!-- Hero Section -->
    <section class="hero-gradient text-white py-20">
        <div class="container mx-auto px-6 text-center">
            <h1 class="text-5xl md:text-6xl font-bold mb-4">
                <i class="fas fa-sync-alt mr-4"></i>旋转数组
            </h1>
            <p class="text-xl md:text-2xl opacity-90 max-w-3xl mx-auto">
                掌握数组旋转的精妙算法，探索翻转法的优雅实现
            </p>
            <div class="mt-8 flex justify-center space-x-4">
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                    <i class="fas fa-clock mr-2"></i>时间复杂度 O(n)
                </span>
                <span class="bg-white bg-opacity-20 px-4 py-2 rounded-full">
                    <i class="fas fa-memory mr-2"></i>空间复杂度 O(1)
                </span>
            </div>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto px-6 py-12 max-w-6xl">
        <!-- Problem Description -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
            <div class="flex items-center mb-6">
                <i class="fas fa-question-circle text-3xl text-purple-600 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">题目描述</h2>
            </div>
            <p class="text-lg text-gray-700 leading-relaxed">
                <span class="drop-cap">给</span>定一个数组，将数组中的元素向右移动 k 个位置，其中 k 是非负数。例如，输入数组 [1, 2, 3, 4, 5, 6, 7] 和 k = 3，数组变为 [5, 6, 7, 1, 2, 3, 4]。
            </p>
            
            <!-- Visual Example -->
            <div class="mt-8 bg-gradient-to-r from-purple-50 to-pink-50 rounded-xl p-6">
                <h3 class="text-xl font-semibold mb-4 text-gray-800">
                    <i class="fas fa-eye mr-2"></i>可视化示例
                </h3>
                <div class="flex items-center justify-center space-x-2">
                    <div class="flex space-x-1">
                        <span class="bg-gray-200 px-3 py-2 rounded">1</span>
                        <span class="bg-gray-200 px-3 py-2 rounded">2</span>
                        <span class="bg-gray-200 px-3 py-2 rounded">3</span>
                        <span class="bg-gray-200 px-3 py-2 rounded">4</span>
                        <span class="bg-purple-200 px-3 py-2 rounded">5</span>
                        <span class="bg-purple-200 px-3 py-2 rounded">6</span>
                        <span class="bg-purple-200 px-3 py-2 rounded">7</span>
                    </div>
                    <i class="fas fa-arrow-right text-2xl text-purple-600 mx-4"></i>
                    <div class="flex space-x-1">
                        <span class="bg-purple-200 px-3 py-2 rounded">5</span>
                        <span class="bg-purple-200 px-3 py-2 rounded">6</span>
                        <span class="bg-purple-200 px-3 py-2 rounded">7</span>
                        <span class="bg-gray-200 px-3 py-2 rounded">1</span>
                        <span class="bg-gray-200 px-3 py-2 rounded">2</span>
                        <span class="bg-gray-200 px-3 py-2 rounded">3</span>
                        <span class="bg-gray-200 px-3 py-2 rounded">4</span>
                    </div>
                </div>
                <p class="text-center mt-4 text-gray-600">k = 3</p>
            </div>
        </section>

        <!-- Core Concepts -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
            <div class="flex items-center mb-6">
                <i class="fas fa-lightbulb text-3xl text-yellow-500 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">核心考点</h2>
            </div>
            <div class="grid md:grid-cols-2 gap-6">
                <div class="bg-gradient-to-br from-blue-50 to-indigo-50 rounded-xl p-6">
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">
                        <i class="fas fa-code mr-2 text-blue-600"></i>数组操作
                    </h3>
                    <p class="text-gray-700">掌握数组的基本操作，包括元素交换、遍历和索引计算等核心技能。</p>
                </div>
                <div class="bg-gradient-to-br from-green-50 to-emerald-50 rounded-xl p-6">
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">
                        <i class="fas fa-sync mr-2 text-green-600"></i>翻转法
                    </h3>
                    <p class="text-gray-700">理解并实现高效的翻转算法，通过三次翻转完成数组旋转。</p>
                </div>
            </div>
        </section>

        <!-- Solution Approaches -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-8">
            <div class="flex items-center mb-6">
                <i class="fas fa-route text-3xl text-green-600 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">解题思路</h2>
            </div>

            <!-- Approach 1: Reverse Method -->
            <div class="mb-8 border-l-4 border-purple-600 pl-6">
                <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                    <i class="fas fa-star text-yellow-400 mr-2"></i>方法一：翻转法（推荐）
                </h3>
                <p class="text-gray-700 mb-4">将数组旋转 k 次可以分为三步：</p>
                
                <div class="space-y-4">
                    <div class="flex items-start space-x-4">
                        <div class="step-number">1</div>
                        <div class="flex-1">
                            <h4 class="font-semibold text-gray-800">翻转整个数组</h4>
                            <p class="text-gray-600">[1,2,3,4,5,6,7] → [7,6,5,4,3,2,1]</p>
                        </div>
                    </div>
                    <div class="flex items-start space-x-4">
                        <div class="step-number">2</div>
                        <div class="flex-1">
                            <h4 class="font-semibold text-gray-800">翻转前 k 个元素</h4>
                            <p class="text-gray-600">[7,6,5,4,3,2,1] → [5,6,7,4,3,2,1]</p>
                        </div>
                    </div>
                    <div class="flex items-start space-x-4">
                        <div class="step-number">3</div>
                        <div class="flex-1">
                            <h4 class="font-semibold text-gray-800">翻转剩余元素</h4>
                            <p class="text-gray-600">[5,6,7,4,3,2,1] → [5,6,7,1,2,3,4]</p>
                        </div>
                    </div>
                </div>
                
                <div class="mt-4">
                    <span class="complexity-badge">
                        <i class="fas fa-clock mr-1"></i>时间 O(n)
                    </span>
                    <span class="complexity-badge">
                        <i class="fas fa-memory mr-1"></i>空间 O(1)
                    </span>
                </div>
            </div>

            <!-- Approach 2: One by One -->
            <div class="mb-8 border-l-4 border-gray-400 pl-6">
                <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                    方法二：逐个移动法
                </h3>
                <p class="text-gray-700 mb-4">每次将数组整体向右移动一位，重复 k 次。</p>
                <div class="bg-red-50 rounded-lg p-4">
                    <p class="text-red-700">
                        <i class="fas fa-exclamation-triangle mr-2"></i>
                        不推荐：时间复杂度较高，效率低下
                    </p>
                </div>
                <div class="mt-4">
                    <span class="complexity-badge bg-red-500">
                        <i class="fas fa-clock mr-1"></i>时间 O(n×k)
                    </span>
                    <span class="complexity-badge">
                        <i class="fas fa-memory mr-1"></i>空间 O(1)
                    </span>
                </div>
            </div>

            <!-- Approach 3: Extra Array -->
            <div class="border-l-4 border-gray-400 pl-6">
                <h3 class="text-2xl font-semibold mb-4 text-gray-800">
                    方法三：使用额外数组
                </h3>
                <p class="text-gray-700 mb-4">创建一个新数组，将元素按旋转后的位置放置。</p>
                <div class="mt-4">
                    <span class="complexity-badge">
                        <i class="fas fa-clock mr-1"></i>时间 O(n)
                    </span>
                    <span class="complexity-badge bg-yellow-500">
                        <i class="fas fa-memory mr-1"></i>空间 O(n)
                    </span>
                </div>
            </div>
        </section>

        <!-- Algorithm Visualization -->
        <section class="bg-white rounded-2xl shadow-xl p-8 mb-8 card-hover">
            <div class="flex items-center mb-6">
                <i class="fas fa-project-diagram text-3xl text-indigo-600 mr-4"></i>
                <h2 class="text-3xl font-bold text-gray-800">算法流程图</h2>
            </div>
            <div class="mermaid">
                graph TD
                    A[开始] --> B[计算 k = k % n]
                    B --> C[翻转整个数组]
                    C -->